<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <canvas id="c" width="800" height="800" style="border: 1px solid #ccc"></canvas>

        <script>
            const cnv = document.getElementById('c')
            const ctx = cnv.getContext('2d')

            ctx.fillStyle = 'red'
            ctx.fillRect(0, 0, 100, 100)
            ctx.save()
            ctx.fillStyle = 'blue'
            ctx.fillRect(100, 100, 100, 100)
            ctx.save()
            ctx.fillStyle = 'yellow'
            ctx.fillRect(200, 200, 100, 100)
            ctx.save()
            ctx.fillStyle = 'green'
            ctx.fillRect(300, 300, 100, 100)

            ctx.restore()
            ctx.fillRect(400, 400, 100, 100)
        </script>
    </body>
</html>
